#!/bin/bash

# 定义变量
APP_NAME="myapp"
APP_VERSION="1.0"
EXECUTABLE="your_executable"
ICON_PATH="/path/to/your/icon.png"
PACKAGE_DIR="myapp_package"

# 创建临时目录
mkdir -p $PACKAGE_DIR/usr/local/bin
mkdir -p $PACKAGE_DIR/usr/local/lib
mkdir -p $PACKAGE_DIR/usr/share/applications

# 复制执行程序
cp $EXECUTABLE $PACKAGE_DIR/usr/local/bin

# 复制依赖库
for lib in $(ldd $EXECUTABLE | grep -o '/[^ ]*'); do
    cp $lib $PACKAGE_DIR/usr/local/lib
done

# 修改执行程序的动态链接库路径
patchelf --set-rpath '$ORIGIN/../lib' $PACKAGE_DIR/usr/local/bin/$EXECUTABLE

# 创建 .desktop 文件
cat << EOF > $PACKAGE_DIR/usr/share/applications/${APP_NAME}.desktop
[Desktop Entry]
Name=$APP_NAME
Exec=/usr/local/bin/$EXECUTABLE
Icon=$ICON_PATH
Terminal=false
Type=Application
Categories=Utility;
EOF

# 打包成 deb 包
fpm -s dir -t deb -n $APP_NAME -v $APP_VERSION -C $PACKAGE_DIR .

# 清理临时目录
rm -rf $PACKAGE_DIR

#sudo apt-get update
#sudo apt-get install patchelf chrpath ruby-dev
#sudo gem install fpm

#chmod +x package.sh
#./package.sh
